// 生成模拟消息数据
const createMockMessages = (chatId, aiName) => {
  // 基于聊天ID生成确定的消息数量
  const chatIdEnd = chatId.substring(chatId.length - 4);
  const messageCount = (parseInt(chatIdEnd, 16) % 6) + 1; // 1-6 条消息
  
  const baseMessages = [];
  
  // 添加欢迎消息
  baseMessages.push({
    id: `welcome-${chatId}`,
    type: 'system',
    sender: aiName,
    collapsible: true,
    collapsed: false,
    content: `欢迎使用聊天系统，这是对话 ${chatId.substring(0, 8)}。您可以开始输入消息进行交流。`,
    time: new Date(Date.now() - 1000 * 60 * 60 * 24 * 2).toISOString(), // 2 days ago
  });
  
  // 添加对话消息
  for (let i = 0; i < messageCount; i++) {
    // 用户消息
    baseMessages.push({
      id: `user-${chatId}-${i}`,
      type: 'user',
      sender: 'lkun233',
      content: `这是测试消息 ${i + 1} 在对话 ${chatId.substring(0, 6)}`,
      time: new Date(Date.now() - 1000 * 60 * 60 * (messageCount - i)).toISOString(),
    });
    
    // AI回复
    baseMessages.push({
      id: `ai-${chatId}-${i}`,
      type: 'system',
      sender: aiName,
      content: `这是第 ${i + 1} 条消息的回复。我是 ${aiName}，很高兴为您服务。`,
      time: new Date(Date.now() - 1000 * 60 * 60 * (messageCount - i) + 1000 * 60 * 2).toISOString(),
    });
  }
  
  return baseMessages;
};

// 获取特定聊天的AI名称
const getAiNameForChat = (chatId) => {
  const aiNames = ['DeepSeekV3', '星火认知大模型', 'GPT-4', 'Claude', 'Gemini', 'Qwen', 'Baichuan'];
  const index = parseInt(chatId.substring(0, 2), 16) % aiNames.length;
  return aiNames[index];
};

// 预定义一些聊天ID用于测试
const chatIds = [
  '5f87c7d1-56a6-4c7a-8840-51f1b35e8f0d',
  '8c22e320-9e1a-42d6-9464-f4fe97e1b21c',
  'c7452f9c-64bf-4a70-8a3e-a5c5ebf1c23b',
  'e8fbd6f0-e180-41b6-92b8-37ed9e7da59f',
  '1d2e3f4a-5b6c-7d8e-9f0a-1b2c3d4e5f6a',
  'a1b2c3d4-e5f6-a7b8-c9d0-e1f2a3b4c5d6',
  'f1e2d3c4-b5a6-9f8e-7d6c-5b4a3f2e1d0c',
  '1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d'
];

// 生成所有预定义聊天的消息
const mockChatMessages = {};

chatIds.forEach(chatId => {
  const aiName = getAiNameForChat(chatId);
  mockChatMessages[chatId] = createMockMessages(chatId, aiName);
});

// 日期格式化辅助函数
const formatTime = (dateString) => {
  const date = new Date(dateString);
  const now = new Date();
  const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  const yesterday = new Date(today);
  yesterday.setDate(yesterday.getDate() - 1);
  
  if (date >= today) {
    return `今天 ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
  } else if (date >= yesterday) {
    return `昨天 ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
  } else {
    return `${date.getMonth() + 1}月${date.getDate()}日 ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
  }
};

// 使用CommonJS导出
module.exports = {
  mockChatMessages,
  formatTime,
  getAiNameForChat
}; 